<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Steam Daily Deal</title>
    <script type="text/javascript">
        var req;
        var dealEndTime;

        function refreshCountdown() {
            var nowTime = new Date().getTime() / 1000;
            var remaining = dealEndTime - nowTime;
            var hours = Math.floor(remaining / 60 / 60);
            var mins = Math.floor(remaining / 60 - hours * 60);
            var secs = Math.floor(remaining - mins * 60 - hours * 60 * 60);
            document.getElementById('countdown').innerHTML = "&nbsp;" + pad(hours, 2) + ":" + pad(mins, 2) + ":" + pad(secs, 2) + "&nbsp;";

            setTimeout('refreshCountdown()', (1000 - new Date().getTime() % 1000) + 100);
        }

        function pad(num, count) {
            var numZeropad = num + '';
            while (numZeropad.length < count) {
                numZeropad = "0" + numZeropad;
            }
            return numZeropad;
        }

        function parseStoreInfo() {
            if (req.readyState == 4) {
                var body = req.responseText;

                var reg;
                var offset;
                var match;

                // Countdown timer
                reg = /InitDailyDealTimer/g
                match = reg.exec(body);
                offset = match.index;

                reg = /[0-9]+/g
                reg.lastIndex = offset;
                match = reg.exec(body);
                dealEndTime = parseInt(match[0]);
                refreshCountdown();

                // Image and link
                reg = /dailydeal/g
                match = reg.exec(body);
                offset = match.index;

                reg = /http:\/\/[a-zA-Z0-9-_~]+(\.[a-zA-Z0-9-_~]+)*(\/[a-zA-Z0-9-_~.]*)*\??([a-zA-Z0-9-_~]+\=[a-zA-Z0-9-_~]+)*/g
                reg.lastIndex = offset;
                match = reg.exec(body);
                offset = match.index + match[0].length;
                document.getElementById('link').href = match[0];

                reg = /http:\/\/[a-zA-Z0-9-_~]+(\.[a-zA-Z0-9-_~]+)*(\/[a-zA-Z0-9-_~.]*)*\??([a-zA-Z0-9-_~]+\=[a-zA-Z0-9-_~]+)*/g
                reg.lastIndex = offset;
                match = reg.exec(body);
                document.getElementById('image').src = match[0];

                // Discount
                reg = /dailydeal_content/g
                match = reg.exec(body);
                offset = match.index;

                reg = /discount_pct/g
                reg.lastIndex = offset;
                match = reg.exec(body);
                offset = match.index;

                reg = /-[0-9]+%/g
                reg.lastIndex = offset;
                match = reg.exec(body);
                document.getElementById('discount').innerHTML = match[0];

                // Old Price
                reg = /dailydeal_content/g
                match = reg.exec(body);
                offset = match.index;

                reg = /discount_original_price/g
                reg.lastIndex = offset;
                match = reg.exec(body);
                offset = match.index;

                reg = />[^<]*</g
                reg.lastIndex = offset;
                match = reg.exec(body);
                document.getElementById('oldPrice').innerHTML = "was&nbsp;" + match[0].slice(1, match[0].length - 1);

                // New Price
                reg = /dailydeal_content/g
                match = reg.exec(body);
                offset = match.index;

                reg = /discount_final_price/g
                reg.lastIndex = offset;
                match = reg.exec(body);
                offset = match.index;

                reg = />[^<]*</g
                reg.lastIndex = offset;
                match = reg.exec(body);
                document.getElementById('newPrice').innerHTML = match[0].slice(1, match[0].length - 1);

                body = null;
            }
        }

        function getStoreInfo() {
            req = new XMLHttpRequest();
            req.onreadystatechange = parseStoreInfo;
            req.open("GET", "http://store.steampowered.com/", true);
            req.send();
        }
    </script>
</head>
<body onload="getStoreInfo()">
<div style="width:300px;">
    <div>
        <div style="padding: 8px; text-align: right; background-image: url('http://steam-dod.googlecode.com/svn/trunk/blue-shad.png');
            background-repeat: repeat-x; background-color: #8bb9e0">
            <div>
                <span style="font-family: Sans-Serif; font-size: 10pt; font-weight: bold">Deal ends in </span><span id="countdown" style="font-family: Monospace; font-size: 12pt; font-weight: bold;
                        background-color: #404040; color: #8bb9e0">&nbsp;00:00:00&nbsp;</span>
            </div>
            <a id="link" href="">
            <img id="image" src="http://steam-dod.googlecode.com/svn/trunk/game-loading.png" width="100%" />
            </a>
        </div>
        <div style="text-align: right; height: 38px; background: #444444; background-image: url('http://steam-dod.googlecode.com/svn/trunk/steam.png');
            background-repeat: no-repeat; font-family: Sans-Serif; color: #ffffff;">
            <div id="discount" style="padding: 2px; background-color: #4c6b22; display: inline-block; font-size: 22pt; vertical-align: top">
                -00%</div><div style="height:34px;padding: 2px; display: inline-block; background-color: #000000">
                <div id="newPrice" style="text-align: left; font-size: 11pt; font-weight: bold">
                    $0.00 USD</div>
                <div id="oldPrice" style="text-align: left; font-size: 9pt; color: #888888;">
                    was $0.00</div>
            </div>
        </div>
    </div>
    </div>
</body>
</html>
